Package gri.tasks.gui

Source Code of gri.tasks.gui.JobOutputViewer

/*
* File: TaskOutputViewer.java
* Author: Daniel Rogers
* Created on Jan 28, 2008
*
*/
package gri.tasks.gui;

import java.awt.*;
import javax.swing.*;

import gri.tasks.ParameterDef;
import gri.tasks.TaskDef;


import gri.tasks.gui.util.JobEntry;
import gri.tasks.gui.widgets.OutputParameterWidgetFactory;
import gri.tasks.gui.widgets.ParameterWidgetFactory;

import gri.tasks.managers.TaskDescription;

import java.util.List;
import java.util.Map;

import dan.swing.style.AppStyles;

/**
* Displays the outputs of a job in a new frame
*
*
* @author dan.rogers
*/
public class JobOutputViewer implements JobViewer {

  ParameterWidgetFactory widgetFactory;

  // --------------------------------------------------------- Constructors

  public JobOutputViewer(ParameterWidgetFactory widgetFactory) {
    this.widgetFactory = widgetFactory;
  }
  public JobOutputViewer() {
    this(new OutputParameterWidgetFactory());
  }

  // ---------------------------------------------------------- Implementation

  public void showJob(JobEntry job) {
    //System.out.println(task.getId());

    //print outputs:
    List paramDefs = job.getTaskDef().getOutputs();
    Map outputs = job.getController().getOutputs();
   
    for (int i=0; i<paramDefs.size(); i++) {
      ParameterDef paramDef = (ParameterDef)paramDefs.get(i);
      Object value = outputs.get(paramDef.getName());
      System.out.println(value + " (" + paramDef.getDataType() + ")");
    }

    //display outputs:
    JFrame frame = new JFrame("Outputs: Job " + String.valueOf(job.getTaskId()));

    OutputPanel outPanel = new OutputPanel(job);
    JScrollPane outPanel_scroll = new JScrollPane(outPanel);

    frame.getContentPane().add(outPanel_scroll, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);

  }

  class OutputPanel extends JPanel {
   
    public OutputPanel(JobEntry job) {
      super(null);
      super.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

      //ParameterizedTask task = job.getParameterizedTask();

      //header:
      TaskHeaderPanel header = new TaskHeaderPanel();
      TaskDescription taskDesc = job.getTaskDescription();
      if (taskDesc != null)
        header.setTaskDescription(taskDesc);
      AppStyles.applyStyle(header, "TaskHeaderPanel");

      Dimension dim = header.getPreferredSize();
      header.setMaximumSize(new Dimension(Integer.MAX_VALUE, dim.height));

      add(header);


      //outputs:
      TaskDef taskDef = job.getTaskDef();
      ParameterDef [] paramDefs = (ParameterDef [])taskDef.getOutputs().toArray(
          new ParameterDef[0]);
     
      ParameterPanel outPanel = new ParameterPanel(paramDefs, widgetFactory);
      outPanel.setValues(job.getController().getOutputs());

      dim = header.getPreferredSize();
      outPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, dim.height));

      add(outPanel);

      add(Box.createVerticalGlue());
    }
   
  }

}
TOP

Related Classes of gri.tasks.gui.JobOutputViewer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.